package com.code.leetcode.offer;

/**
 * @author codeDorado
 * @version 1.0
 * @date 2020/8/3 10:30
 */
public class The49 {
    public int nthUglyNumber(int n) {
        int[] f = new int[n];
        int[] pos = new int[3];

        f[0] = 1;
        for (int i = 1; i < n; i++) {
            int a = f[pos[0]] * 2;
            int b = f[pos[1]] * 3;
            int c = f[pos[2]] * 5;

            int min = Math.min(Math.min(a, b), c);

            if (a == min) pos[0]++;
            if (b == min) pos[1]++;
            if (c == min) pos[2]++;

            f[i] = min;
        }
        return f[n - 1];
    }
}
